Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 19, 2025

Shell Command Action Feature Implementation ✅

Requirements from Issue

  • Execute shell commands when triggered by a key/button
  • Add a checkbox for root mode
  • Add a test button that shows command output (scrollable)
  • Make it full screen (not a bottom sheet) due to potentially large output

Recent Changes

  • Refactored UI to use ShellCommandActionState data class instead of separate parameters
  • Updated ViewModel to use KMError.getFullMessage() with ResourceProvider for better error messages
  • Added ActionEntity mapper conversion for database persistence with useRoot flag

Implementation Summary

The shell command action feature has been fully implemented with the following capabilities:

User Interface:

  • Full-screen configuration UI (not a bottom sheet as requested)
  • Command input field (multi-line, supports up to 10 lines)
  • "Run as root" checkbox for executing commands with superuser privileges
  • Test button to execute the command and see output before saving
  • Scrollable output display with monospace font
  • Error handling with user-friendly messages using ResourceProvider

Technical Implementation:

  • Uses ShellCommandActionState data class for cleaner state management
  • Uses ShellAdapter for normal shell commands
  • Uses SuAdapter for root commands (requires root permission)
  • Supports command output capture for testing
  • Error messages use KMError.getFullMessage() for consistent localization
  • Proper database persistence through ActionEntity mapper
  • Action is serializable and editable
  • Integrates seamlessly with existing action system

Files Modified/Created:

  1. ActionId.kt - Added SHELL_COMMAND action ID
  2. ActionData.kt - Added ShellCommand data class
  3. ActionUtils.kt - Added category, title, icon mappings, and isEditable
  4. CreateActionDelegate.kt - Added configuration logic
  5. PerformActionsUseCase.kt - Added execution logic
  6. strings.xml - Added new string resources
  7. ShellCommandActionScreen.kt - Full-screen UI with ShellCommandActionState
  8. ConfigShellCommandViewModel.kt - ViewModel with state management and ResourceProvider
  9. NavDestination.kt - Added ConfigShellCommand navigation destination
  10. BaseMainNavHost.kt - Registered shell command screen in navigation
  11. SuAdapter.kt - Added executeWithOutput method for root commands with output capture
  12. ActionUiHelper.kt - Added shell command description display logic
  13. ShellCommandActionTest.kt - Unit tests for shell command action
  14. ActionEntity.kt - Added SHELL_COMMAND type and ACTION_FLAG_SHELL_COMMAND_USE_ROOT flag
  15. ActionDataEntityMapper.kt - Added conversion logic for database persistence
Original prompt

This section details on the original issue you should resolve

<issue_title>Add action: executing shell command</issue_title>
<issue_description>Developer TODO (don't remove)

  • Add a checkbox for root mode
  • Add a test button when setting up that shows you the output, make sure it is scrollable.
  • Make it full screen and not a bottom sheet because there is potentially a lot to write/output.

Hi developer(s), thank you for great KeyMapper!

It would be nice to run a shell command when I trigger by a key/button.


Also, I'm looking for a way to combine KeyMapper with https://github.com/renyuneyun/Easer . Easer can set a user-custom shell command as action, but it can't set a key/button as trigger.

renyuneyun/Easer#376</issue_description>

Comments on the Issue (you are @copilot in this section)

@sds100 Hello! Does Easer allow you to create launcher shortcuts for actions? If so then maybe the App Shortcut action will work in Key Mapper. @sds100 Oh okay. Can you trigger Easer actions with Intents? There is an action in Key Mapper to send an intent @sds100 Yeah, a broadcast is a way for an app to send an intent to another app. In that case you'll want to create an Intent action in Key Mapper and choose the "broadcast receiver" target. Set the Intent action in Easer (in your screenshot) to be the same as in Key Mapper. @sds100 Yeah, that works. I'll still leave the shell command feature request open

Fixes #661


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI changed the title [WIP] Add action for executing shell command with trigger Add shell command action with root mode support and test functionality Oct 19, 2025
Copilot AI requested a review from sds100 October 19, 2025 15:33
@sds100 sds100 marked this pull request as ready for review October 19, 2025 15:42
@sds100 sds100 self-requested a review October 19, 2025 18:30
@sds100 sds100 removed their assignment Oct 19, 2025
Copy link
Collaborator

@sds100 sds100 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot can you implement this review.


testResult = when (result) {
is Success -> State.Data(result.data)
is KMError -> State.Data("Error: ${formatError(result)}")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot use KMError.getFullMessage() which requires a ResourceProvider

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated error handling to use KMError.getFullMessage(resourceProvider) for consistent, localized error messages. Added ResourceProvider to ViewModel constructor. (commit: in progress)

@sds100 sds100 merged commit beb0747 into develop Oct 19, 2025
1 of 3 checks passed
@sds100 sds100 deleted the copilot/add-shell-command-execution branch October 19, 2025 23:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add action: executing shell command

2 participants